#ifndef Com_Mod
#define Com_Mod
#include <boost/asio.hpp>
#define PORT "COM8"

using namespace::boost::asio;  
using namespace std;


class Communicator{

public:

	int  X, Y;

	//io_service object is needed for creating a serial port, it is used to read an write data to an io device (serial port).
	io_service io;

	
	//Union is reserves a memory space for the biggest variable(struct) in the union and this way we can send the data over in bytes.
	//This is possible because all the variables in the union have the same memory space witout any seperation.
	//Now we can send the struct in the union in byte parts over since the are one and the same memory space.
	//Note that only one variable type can be accesed at aany given time, since there is only data for one variable in the reserverd union memory space.
	union SendPacked{
		struct test{
			int32_t Y;
			int32_t X;
		    int32_t AngleX;
            int32_t AngleY;
		} Struc;

		unsigned char bytes[16];
	} SendData;

		union RecvPacked{
		struct test{
			int32_t Y;
			int32_t X;
		    int32_t AngleX;
            int32_t AngleY;
		} Struc;

		unsigned char bytes[16];
	} RecvData;

	//Default constructor creates an instance of a serial port with the given parameters (io service object and comport name).
	Communicator() : port(io, PORT){};

	serial_port port;

	~Communicator(){};

	//Class functions
	void Setup();
	void Send(int X, int Y, int AngleX, int AngleY);
	void Send2();
	void Recieve();
	void Read(char* Buffer);

private:
	int x, y;
};

#endif
